/**
 * @package: com.mys.springboot.config.i18n
 * @fileName: I18nConfig.java
 */
package com.mys.springboot.config.i18n;

import java.util.Locale;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;

/**
 * @description:
 * @createdTime: 2016年11月7日 下午2:53:36
 * @createdUser: mys
 * @lastUpdatedTime:
 * @lastUpdatedUser:
 * @version: 1.0
 */
@Configuration
public class I18nConfig {

	@Bean
	public ResourceBundleMessageSource messageSource() {
		ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
		messageSource.setBasenames("i18n/messages");
		messageSource.setUseCodeAsDefaultMessage(true);
		messageSource.setDefaultEncoding("UTF-8");
		messageSource.setCacheSeconds(3);
		
		return messageSource;
	}

	@Bean
	public CookieLocaleResolver localeResolver() {
		CookieLocaleResolver localeResolver = new CookieLocaleResolver();
		localeResolver.setCookieMaxAge(604800);
		// 设置默认语种为英文
		localeResolver.setDefaultLocale(new Locale("en", "US"));
		localeResolver.setCookieName("org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE");
		return localeResolver;
	}
}
